import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'
import Space from '@/layout/space'

const userRoutes = [
  {
    path: '/user',
    component: Space,
    children: []
  }
]

const homeRoutes = [
  {
    path: '/',
    component: Layout,
    // redirect: '/home',
    children: [
      // {
      //   path: '/test',
      //   component: () => import('@/views/test/test_rpc'),
      //   name: '/test'
      // }
    ]
  }
]

const allRoutes = [...userRoutes, ...homeRoutes]

const createRouter = () => {
  return new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: allRoutes
  })
}

const router = createRouter()

// router.beforeEach(async (to, from, next) => {
//   const whiteList = ['/user/login', '/test']
//   if (whiteList.includes(to.path)) {
//     next()
//     return
//   }

//   const hasToken = await api.session_check()

//   if (!hasToken) {
//     next(`/user/login?redirect=${to.path}`)
//     return
//   }

//   next()
//   return
// })

export default router
